<template>
	<el-container v-if="isAlready">
		<el-header>
			<div class="left-panel">
				<fsButton ref="button" plain size="default" :buttons="buttons" @clickHandler="buttonHandler"></fsButton>
			</div>
			<div class="right-panel">
				<ex-search ref="search" :searches="searches" @searchOk="searchHandler" default-code="changeAfter.code" placeholder="请输入资产编码" :fixedParam="fixedParams" :initParams="searchParams"></ex-search>
			</div>
		</el-header>
		<el-main class="nopadding">
			<ex-table id="checkTaskTable" ref="table" :tablename="'资产履历查询'" :columns="columns" :url="this.$API.asset.assetLog.list.url" :refs="this.$refs" search="search" @columnClick="columnClickHandler"></ex-table>
		</el-main>
	</el-container>
	<data-card ref="dataCard"></data-card>
</template>

<script>
import ExTable from "@/components/exTable/index.vue";
import ExSearch from "@/components/exSearch/index.vue";
import ExTreeNavigation from "@/components/exSearchTree/index.vue";
import ExSearchTree from "@/components/exSearchTree/index.vue";
import scSelectFilter from "@/components/scSelectFilter/index.vue";
import tool from "@/utils/tool";
import DataCard from "@/views/asset/card/card.vue";
import useTabs from "@/utils/useTabs";
import globalparam from "@/constant/model/globalparam";
import BaseTemplate from "@/utils/baseTemplate";
export default {
	name: '资产履历信息',
	components: {
		DataCard,
		scSelectFilter,
		ExSearchTree,
		ExTreeNavigation,
		ExSearch,
		ExTable,
	},
	data() {
		return {
			dialog: {
				save: false,
				permission: false,
			},
			apiObj: [],
			buttons: [
				{name: "导出", icon: "el-icon-download", click: "export", type: "info", permission: "export"},
			],
			searches: [
				{type: "tree-select", name: "管理部门", code: "dutyDepartmentIds", placeholder: "请选择管理部门", dictCode:'SysOrganization',checkStrictly:true,multiple:true,dataPermissionProcess:true},
				{type: "select", name: "操作类型", code: "documentInfo.processTypeId", placeholder: "请选择操作类型", dictCode:'FamsDocumentProcessType'},
				{type: "input", name: "资产编码", code: "changeAfter.code", placeholder: "请输入资产编码", maxlength: 30, showLimit: true},
				{type: "tree-select", name: "资产分类", code: "assetCategoryIds", placeholder: "请选择资产分类", dictCode:'FamsAssetCategory',checkStrictly:true,multiple:true,dataPermissionProcess:true},
				{type: "select", name: "资产状态", code: "assetStatusIds", placeholder: "请选择资产状态", dictCode:'ASSET_STATUS',multiple:true},
				{type: "tree-select", name: "使用部门", code: "usingDepartmentIds", placeholder: "请选择使用部门", dictCode:'SysOrganization',checkStrictly:true,multiple:true,dataPermissionProcess:true},
				{type: "selector", name: "使用人", code: "changeAfter.usingMenId", placeholder: "请选择使用人", dictCode:'SysUser'},
				{type: "daterange", name: "操作日期", code: "createTimeStart,createTimeEnd", placeholder: "请选择操作日期", formatter:"YYYY-MM-dd",valueFormat:"YYYYMMDD",range:365},
				{type: "daterange", name: "购置日期", code: "boughtDateStart,boughtDateEnd", placeholder: "请选择购置日期", formatter:"YYYY-MM-dd",valueFormat:"YYYYMMDD",range:365},
				{type: "daterange", name: "维修完成日期", code: "zcbxFinishDateStart,zcbxFinishDateEnd", placeholder: "请选择维修完成日期", formatter:"YYYY-MM-dd",valueFormat:"YYYYMMDD",range:365},
				{type: "daterange", name: "调拨日期", code: "zcdbDateStart,zcdbDateEnd", placeholder: "请选择调拨日期", formatter:"YYYY-MM-dd",valueFormat:"YYYYMMDD",range:365},
				{type: "daterange", name: "转移日期", code: "zczyDateStart,zczyDateEnd", placeholder: "请选择转移日期", formatter:"YYYY-MM-dd",valueFormat:"YYYYMMDD",range:365},
				{type: "daterange", name: "报废日期", code: "scrapDateStart,scrapDateEnd", placeholder: "请选择报废日期", formatter:"YYYY-MM-dd",valueFormat:"YYYYMMDD",range:365},
				{type: "daterange", name: "领用日期", code: "recipientOnDateStart,recipientOnDateEnd", placeholder: "请选择领用日期", formatter:"YYYY-MM-dd",valueFormat:"YYYYMMDD",range:365},
			],
			columns: [
				{code: "详细", name: "详细", width:"50",fixedValue:"详细",click:"toAsset"},
				{code: "documentInfo.code", name: "单据编号", width:"120",click:"toDocument"},
				{code: "documentInfo.documentConfigId", name: "单据类型", width:"100",formatter:"DICT",key: "FamsDocumentConfig"},
				{code: "documentInfo.processTypeId", name: "处理方式", width:"",formatter:"DICT",key: "FamsDocumentProcessType"},
				{code: "documentInfo.status", name: "单据状态", width:"75",formatter:"DICT",key: "DOCUMENT_STATUS"},
				{code: "changeAfter.assetStatusId", name: "资产状态", width:"75",formatter:"DICT",key: "ASSET_STATUS"},
				{code: "changeAfter.code", name: "资产编码", width:"130",click:"show1"},
				{code: "changeAfter.financialCode", name: "财务编码", width:"120"},
				{code: "changeAfter.name", name: "资产名称", width:"200"},
				{code: "changeAfter.mainCategoryCode", name: "资产大类",width:"150", formatter:"DICT",key: "FamsAssetCategory"},
				{code: "changeAfter.assetCategoryId", name: "资产小类",width:"150", formatter:"DICT",key: "FamsAssetCategory"},
				{code: "changeAfter.storePlaceId", name: "资产位置",width: "120", formatter:"DICT",key: "FamsPosition"},
				{code: "changeAfter.other.financialBarCode", name: "财务条形码", width:"100"},
				{code: "changeAfter.other.purchaseOrderCode", name: "申购单号", width:"100"},
				{code: "changeAfter.brand", name: "品牌", width:"100"},
				{code: "changeAfter.model", name: "规格型号", width:"150"},
				{code: "changeAfter.serialCode", name: "资产序列号", width:"150"},
				{code: "changeAfter.assetCount", name: "数量", width:"50",summary:true},
				{code: "changeAfter.originalValue", name: "资产原值", width:"100",summary:true},
				{code: "changeAfter.netValue", name: "资产净值", width:"100",summary:true},
				{code: "changeAfter.usingMenId", name: "使用人", width:"80",formatter: "DICT",key: "SysUser"},
				{code: "changeAfter.usingDepartmentId", name: "使用部门", width:"100",formatter: "DICT",key: "SysOrganization"},
				{code: "changeAfter.dutyDepartmentId", name: "管理部门", width:"100",formatter: "DICT",key: "SysOrganization"},
				{code: "changeAfter.boughtDate", name: "购置日期", width:"95",formatter: "DATE"},
				{code: "changeAfter.recipientOnDate", name: "领用日期", width:"95",formatter: "DATE"},
				{code: "documentInfo.createUser", name: "操作人", width:"80",formatter: "DICT",key: "SysUser"},
				{code: "documentInfo.createTime", name: "操作日期", width:"95",formatter: "DATE"},
			],
			parentLevelCode:"",
			assetIds:[],
			loading: false,
			isAlready:false,
			loginUsers: tool.current.user(),
			searchParams:{},
			fixedParams:{
				deptIds:this.$TOOL.current.manageDeptIds(),
				assetStatisticsRange:"",
			},
		}
	},
	created() {
		//如果是通过跳转过来的，标签的名称设置为跳转后的标题
		let routeParams = this.$store.state.routeParams[this.$route.params.key];
		if(routeParams){
			if(routeParams.title){
				useTabs.setTitle(routeParams.title);
				document.title = routeParams.title;
			}
			if (routeParams.fixedParams) {
				Object.assign(this.fixedParams,routeParams.fixedParams);
			}
			if (routeParams.searchParams) {
				Object.assign(this.searchParams,routeParams.searchParams);
			}
		}
		this.isAlready = true;
	},
	mounted() {
	},
	beforeMount() {
		this.$cache.data.loadGlobalParam(globalparam.assetStatisticsRange.paramCode).then(res=>{
			this.fixedParams.assetStatisticsRange = res;
		});
	},
	methods: {
		buttonHandler(index, name) {
			this.$options.methods[name](this, index);
		},
		async searchHandler() {
			let queryParams = {pathCode: this.parentLevelCode}
			await this.$refs.table.refresh(queryParams);
		},
		columnClickHandler(name,data){
			this.$options.methods[name](this, data);
		},
		//查看
		async show1(_this, row) {
			let assetCategory = await _this.$cache.data.loadAssetCategory(row.changeAfter.assetCategoryId);
			try {
				_this.loading = true;
				let entity = {cardId: assetCategory.assetCardId, _editFlag: false}
				_this.$nextTick(() => {
					_this.cardPreview = false;
					_this.$refs.dataCard.open(Object.assign(entity, row.changeAfter));
				});
			} finally {
				_this.loading = false;
			}
		},
		//导出
		async export(_this,index) {
      let attachParams = {};
      let exportApi = _this.$API.asset.assetLog.export;
      let exTableRef = _this.$refs.table;
      let exportBtnRef = _this.$refs.button;
      let exportBtnIndex = index;
      await BaseTemplate.export(_this, exportApi, attachParams, exportBtnRef, exportBtnIndex, exTableRef);

		},
		toDocument(_this,row){
			_this.$nextTick(() => {
				_this.$router.push({name:"documentPrepare",params:{fromRouteId:_this.$TOOL.crypto.MD5(_this.$route.path),configId:row.documentInfo.documentConfigId,id:row.documentId}});
			})
		},
		async toAsset(_this, row) {
			try {
				_this.loading = true;
				_this.dataCardShow = true;
				let rsp = await _this.$API.asset.document.findById.post({id: row.documentId});
				if (rsp.code === 2000) {
					let document = rsp.data;
					let entity = {modelId: row.documentId, cardId: document.processType.showCardId, _editFlag: false}
					if(row.documentDetailId){
						let res = await _this.$API.asset.documentDetail.findById.post({id: row.documentDetailId});
						if (res.code === 2000) {
							_this.$nextTick(() => {
								_this.$refs.dataCard.open(Object.assign(entity, res.data));
							});
						}
					}
				}

			} finally {
				_this.loading = false;
			}
		},
	}
}

</script>
<style scoped>

</style>
